package com.chengh.vhr.service.serviceImpl;

import com.chengh.vhr.mapper.RoleMapper;
import com.chengh.vhr.model.Role;
import com.chengh.vhr.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    RoleMapper roleMapper;

    @Override
    public List<Role> getAllRole() {
        return roleMapper.getAllRole();
    }

    @Override
    public Integer addRole(Role role) {
        if(!role.getName().startsWith("ROLE_")) {
            role.setName("ROLE_" + role.getName());
        }
        return roleMapper.insert(role);
    }

    @Override
    public Integer deleteByRid(Integer rid) {
        return roleMapper.deleteByPrimaryKey(rid);
    }
}
